package leetcode.n2022;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;

/**
 * 1576. 替换所有的问号
 * https://leetcode-cn.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters/
 *
 * @Author: Chaos
 * @Date: 2022/1/18
 */
public class ModifyString {


    public String modifyString(String s) {

        char[] chars = s.toCharArray();

        for (int i = 0; i < chars.length; i++) {
            System.out.println((int) chars[i]);
            if ((int) chars[i] == 63) {
                int a = 97;
                int b = 97;
                int c = 63;
                if (i - 1 >= 0) {
                    a = chars[i - 1];
                }
                if (i + 1 < chars.length) {
                    b = chars[i + 1];
                }
                while (c == a || c == b || c <= 96) {
                    c++;
                }
                chars[i] = (char) c;
            }
        }

        return String.valueOf(chars);
    }


    public static void main(String[] args) {
        Log log = LogFactory.get();

        ModifyString modifyString = new ModifyString();

        String s = "??yw?ipkj?";
        String result = modifyString.modifyString(s);

        log.info(result);
    }
}
